/* PDPBrandGradingOcid: "PDPBrandGradingOcid",
    PDPBrandGradingReadLink: "PDPBrandGradingReadLink",
    PDPBrandGradingWriteLink: "PDPBrandGradingWriteLink" */

async function updateRecord(object, iframeWindow, formContext, iframeWindow1) {
  await ConfigurationOpt.InitGlobalConfigurationPromise();
  var url = ConfigurationOpt.GetConfigurationValueSync(
    ConfigurationOpt.ConfigurationKeys.PDPBrandGradingReadLink
  );
var ocid=ConfigurationOpt.GetConfigurationValueSync(
    ConfigurationOpt.ConfigurationKeys.PDPBrandGradingOcid
  );

url=url+"&"+ocid;
  url = url.replace("{ocid}", ocid);
  var maxRetries = 3;
  var attempt = 0;
 
  function sendRequest() {
    var req = new XMLHttpRequest();
    req.open("GET", url, true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
 
    req.onreadystatechange = function () {
      if (this.readyState == 4) {
        // 请求完成
        req.onreadystatechange = null;
        if (this.status == 200) {
          SendCMSHelper.HideLoading();
          savetoBDT(iframeWindow, formContext, iframeWindow1);
        } else if (this.status == 412) {
          SendCMSHelper.ShowLoading("Request failed, retrying...");
          if (attempt < maxRetries) {
            attempt++;
            setTimeout(sendRequest, 200); // 等待 200ms 后重试
          } else {
            SendCMSHelper.HideLoading();
            Xrm.Utility.alertDialog(
              "There is something wrong in updating cross market. Someone else may be modifying this partner. Please retry after 10 seconds."
            );
          }
        } else {
          SendCMSHelper.HideLoading();
          Xrm.Utility.alertDialog(
            "There is something wrong in updating cross market. Please retry after 10 seconds."
          );
        }
      }
    };
 
    req.send(JSON.stringify(object));
  }
 
  sendRequest(); // 发送请求

}